package com.youlu.campus.web.job.controller;

import com.youlu.campus.entity.ActivityUserJobInfo;
import com.youlu.campus.entity.VO.JobInfoVO;
import com.youlu.campus.entity.VO.req.FavoriteJboQueryVO;
import com.youlu.campus.service.job.JobInfoService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 工作信息
 *
 * @author: zhuhuaiqi
 */
@RestController
public class JobInfoController {
    @Autowired
    private JobInfoService jobInfoService;

    /**
     * 工作列表
     */
    @PostMapping("/mini-app/job-info/list")
    public QResult list(@RequestBody @Valid JobInfoVO request) {
        request.setUserId(RequestContext.getUserId());
        return QResult.success(jobInfoService.list(request));
    }

    /**
     * 我参与的工作列表
     */
    @PostMapping("/mini-app/job-info/my/list")
    public QResult myJobs(@RequestBody @Valid JobInfoVO request) {
        request.setUserId(RequestContext.getUserId());
        return QResult.success(jobInfoService.myJobs(request));
    }

    /**
     * 收藏工作列表
     */
    @PostMapping("/mini-app/job-info/favorite/list")
    public QResult favoritedList(@RequestBody @Valid FavoriteJboQueryVO request) {
        request.setUserId(RequestContext.getUserId());
        return QResult.success(jobInfoService.favoriteJobList(request));

    }

    /**
     * 工作详情
     */
    @GetMapping("/mini-app/job-info/detail")
    public QResult getDetail(@RequestParam("id") String id) {
        final String userId = RequestContext.getUserId();
        return QResult.success(jobInfoService.getDetail(userId, id));
    }

    /**
     * 收藏工作
     */
    @GetMapping("/mini-app/job-info/favorite")
    public QResult favoriteJob(@RequestParam("id") String id) {
        final String userId = RequestContext.getUserId();
        return QResult.success(jobInfoService.favoriteJob(userId, id));
    }

    /**
     * 取消收藏工作
     */
    @GetMapping("/mini-app/job-info/unfavorite")
    public QResult unFavoriteJob(@RequestParam("id") String id) {
        final String userId = RequestContext.getUserId();
        return QResult.success(jobInfoService.unFavoriteJob(userId, id));
    }

    /**
     * 报名工作
     */
    @PostMapping("/mini-app/join-job")
    public QResult joinJob(@RequestBody ActivityUserJobInfo jobInfo) {
        final String userId = RequestContext.getUserId();
        return QResult.success(jobInfoService.joinJob(jobInfo, userId));
    }

    /**
     * 企业信息
     */
    @GetMapping("/mini-app/job-info/enterprise")
    public QResult getEnterprise(@RequestParam("id") String id) {
        final String userId = RequestContext.getUserId();
        return QResult.success(jobInfoService.getEnterpriseJobInfo(id));
    }
}